<?php
include APPPATH.'classes/datepicker.php';
include APPPATH.'classes/accordion.php';
include APPPATH.'classes/button.php';

class jquery{
	var $CI;
	var $js_files;
	var $css_files;
	var $theme;
	var $output;
	//This is the composite attributes
	public $widgets;
	/**
	 * initialize this class, takes array with these parameters
	 * 'theme' => (optional) the selected theme for jquery-ui. the available values are 'ui-lightness'(default), 'start','eggplant'
	 * 'jquery-uiPath' => optional will choose from assets/jquery
	 */
	public function __construct($param=array('theme'=>'ui-lightness')){
		//echo "ww";
		$this->CI = & get_instance();
		
		$this->CI->load->helper('url');
		$this->widgets = array();
		
		if(!isset($param['theme']))
		{
			$this->theme = 'ui-lightness';
		}
		else
		{
			$this->theme = $param['theme'];
		}
		
		if(!isset($param['jquery-uiPath']))
		{
			$this->css_files = array(base_url().'/assets/jquery/css/'.$this->theme.'/jquery-ui-1.8.16.custom.css');
			$this->js_files  = array(base_url().'/assets/jquery/js/jquery-1.6.2.min.js',base_url().'/assets/jquery/js/jquery-ui-1.8.16.custom.min.js');			
		}
		else
		{
			$this->css_files = array($param['jquery-uiPath'].'/css/'.$this->theme.'/jquery-ui-1.8.16.custom.css');
			$this->js_files  = array($param['jquery-uiPath'].'/js/jquery-1.6.2.min.js',$param['jquery-uiPath'].'/js/jquery-ui-1.8.16.custom.min.js');
		}
		
	}
	/**
	 * render all neccesary file for all widget
	 *
	 */
	public function renderHead(){
		$output = array();
		$output['css_files'] = $this->css_files;
		$output['js_files']  = $this->js_files;
		$output['outputHead']  = "\n<script> $(function(){\n";
		foreach($this->widgets as $widget)
		{
			$output['outputHead'] .= $widget->renderHead()."\n";
		}
		$output['outputHead'] .= "});</script>\n";
		
		return $output;
	}
	 
	/**
	 * add a widget to the entity
	 * $name = @String name of the widget (at the moment) available options are
	 *         'DatePicker','Accordion','Button','AnchorButton','CheckButton','RadioButton'
	 * $id   = @string the id
	 */
	public function addWidget($name,$id)
	{
		$this->widgets[$id] = new $name($id);
	}
	
	
	
};

